package com.tenglong.teacher.ui.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.tenglong.teacher.R;
import com.tenglong.teacher.data.resultInfo.BaseHomeWorkInfo;
import com.tenglong.teacher.data.resultInfo.ClassInfo;
import com.tenglong.teacher.data.resultInfo.ClassInfoBean;
import com.tenglong.teacher.data.resultInfo.CurrentHomeWorkOutsideInfo;
import com.tenglong.teacher.data.resultInfo.HistoryHomeWorkOutsideInfo;
import com.tenglong.teacher.data.resultInfo.SeClass;
import com.tenglong.teacher.ui.adapter.viewholder.ClassRecordViewHolder;
import com.tenglong.teacher.ui.adapter.viewholder.HomePagerViewHolder;
import com.tenglong.teacher.ui.adapter.viewholder.base.BaseViewHolder;

import java.util.List;

/**
 * @author hdx on 2019/4/18.
 */
public class HomePagerAdapter extends RecyclerView.Adapter<BaseViewHolder<ClassInfoBean>> {
    private HomePagerListener homePagerListener;
    private ClassRecordListener recordListener;
    private List<ClassInfoBean> infos;
    public HomePagerAdapter(List<ClassInfoBean> infos){
        this.infos = infos;
    }
    @NonNull
    @Override
    public BaseViewHolder<ClassInfoBean> onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        switch (viewType){
            case 0:
                return new HomePagerViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_class,viewGroup,false),homePagerListener);
            default:
                return new ClassRecordViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_class_record_layout,viewGroup,false),recordListener);
        }

    }

    @Override
    public void onBindViewHolder(@NonNull BaseViewHolder<ClassInfoBean> seClassBaseViewHolder, int i) {
        seClassBaseViewHolder.setLayoutInfo(infos.get(i));
    }
    @Override
    public int getItemViewType(int position) {
        ClassInfoBean info = infos.get(position);
        if (info instanceof SeClass){
            return 0;
        } else{
            return 1;
        }
    }
    @Override
    public int getItemCount() {
        return infos.size();
    }

    public void setClassRecordListener(ClassRecordListener recordListener){
        this.recordListener = recordListener;
    }
    public void setHomePagerListener(HomePagerListener homePagerListener){
        this.homePagerListener = homePagerListener;
    }
    public interface ClassRecordListener{
        void onRecordPosition(int position);
    }
    public interface HomePagerListener{
        void onHomePagerListener(int position);
    }
}
